<html class="pixel-ratio-1">
<head>
    <title>添加客户</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="添加客户">

    {include file="common/link" /}
</head>

<body ontouchstart="">
<!--<div class="weui-cells__title">添加客户</div>-->
<!--    <div class="weui-cells weui-cells_form">-->
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">供应商名称</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input validity" type="text"  placeholder="供应商名称" name="nickname">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">联系人</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input validity" type="text"  placeholder="联系人" name="contacts">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input validity mobile" type="text"   placeholder="手机号" name="mobile">
        </div>
    </div>

    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">电话</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input " type="text"  placeholder="请输入电话" name="tel">
        </div>
    </div>

<!--    <div class="weui-cells__title">客户详细地址</div>-->
<!--    <div class="weui-cells weui-cells_form">-->
<!--        <div class="weui-cell">-->
<!--            <div class="weui-cell__bd">-->
<!--                <textarea class="weui-textarea address validity" placeholder="请输入地址" rows="1" name="address"></textarea>-->
<!--                <div class="weui-textarea-counter"><span>0</span>/50</div>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
    <div class="weui-cells__title">供应商备注</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <textarea class="weui-textarea remark " placeholder="请输入备注" rows="2" name="remark"></textarea>
                <div class="weui-textarea-counter"><span>0</span>/200</div>
            </div>
        </div>
    </div>
</div>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips">确定</a>
    </div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>

<script src="__CDN__/assets/web/plugins/fastclick.js"></script>
<script>
    $(function() {
        FastClick.attach(document.body);
    });
</script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="__CDN__/assets/web/layer/layer.js"></script>

<script>
    $('.remark').keyup(function () {      // 按键弹起时触发的事件；
        var len = $(this).val().length
        console.log(len)
        $(this).next().find('span').html(len)
    });

    function isTel(value) {
        var rex = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
        var rex2 = /^\d{3,4}-?\d{7,9}$/;;
        if (rex.test(value) || rex2.test(value)) {
            return true;
        } else {
            return false;
        }
    }
    // 验证手机号
    function isPhoneNo(phone) {
        var pattern = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
        return pattern.test(phone);
    }

    $("#showTooltips").click(function() {
        state = 1;
        $('.validity').each(function () {
            if($(this).val() == ''){
                $(this).show().focus();
                state = 0;
                return false
            }
        })
        if(state == 0){
            layer.msg('你有参数未填写')
            return false
        }



        var  mobile= $('input[name="mobile"]').val()
        var  contacts= $('input[name="contacts"]').val()
        var  nickname= $('input[name="nickname"]').val()
        var  tel= $('input[name="tel"]').val()
        // var  address= $('.address').val()
        var  remark= $('.remark').val()
        if(isPhoneNo(mobile) == false){
            layer.msg('手机号码不正确')
            return false
        }

        var url  = '{$turl}'+'/web/supplier/add';
        $.post(url,{mobile:mobile,contacts:contacts,nickname:nickname,tel:tel,remark:remark},function (res) {
            layer.msg(res.msg)
            if(res.code >0){
                setTimeout(function () {
                    window.parent.location.reload(); //刷新父页面
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);  // 关闭layer
                },800);
            }
        })


        // var
        // var tel = $('#tel').val();
        // var code = $('#code').val();
        // if(!tel || !/1[3|4|5|7|8]\d{9}/.test(tel)) $.toptip('请输入手机号');
        // else if(!code || !/\d{6}/.test(code)) $.toptip('请输入六位手机验证码');
        // else $.toptip('提交成功', 'success');
    });
</script>
</body>
</html>
